<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>小程序文件上传示例</title>
</head>
<body>
<pre>
let _this = this;
wx.chooseImage({
  count: 1,
  sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
  sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
  success: function (res) {
    //common.loading("上传中");
    let file = res.tempFilePaths[0];
    const uploadTask = wx.uploadFile({
      url: `${configs.baseURL}common/file_upload`,//拼接上传地址
      filePath: file,
      name: "files[]",//固定传 files[]
      header: {
        "Services-Mini-Token": wx.getStorageSync("token"),//身份认证token
      },
      formData: {},
      success: function (upres) {
        //common.hideLoading();
        let data = upres.data;
        data = JSON.parse(data);
        let fid = data.fid;//获取上传返回的 fid
        _this.fid = fid;
      },
    });
  },
});
</pre>
</body>
</html>
